//
//  UIImage+Extension.m
//  Safflower
//
//  Created by 袁亮 on 2016/12/7.
//  Copyright © 2016年 Migic_Z. All rights reserved.
//

#import "UIImage+Extension.h"

@implementation UIImage (Extension)

+ (NSString *) imageToBase64String:(UIImage *)image
{
    NSData *data = UIImageJPEGRepresentation(image, 1.0);
    
    NSString *base64String = [data base64EncodedStringWithOptions:0];
    
    return base64String;
}

+ (UIImage *)imageWithColor:(UIColor *)color
{
    CGRect rect = CGRectMake(0.0f, 0.0f, 1.0f, 1.0f);
    UIGraphicsBeginImageContext(rect.size);
    CGContextRef context = UIGraphicsGetCurrentContext();
    
    CGContextSetFillColorWithColor(context, [color CGColor]);
    CGContextFillRect(context, rect);
    
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    
    return image;
}

+(UIImage *)avatarImageWithOriginalImage:(UIImage *)originalImage
{
    CGSize size = CGSizeMake(200, 200);
    UIGraphicsBeginImageContext(size);
    [originalImage drawInRect:CGRectMake(0,0,size.width,size.height)];
    UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return newImage;
}

+(UIImage*)scaleImage:(UIImage *)image multiple:(CGFloat) multiple
{
    CGSize size = CGSizeMake(image.size.width * multiple, image.size.height * multiple);
    
    UIGraphicsBeginImageContext(size);
    
    [image drawInRect:CGRectMake(0,0,size.width,size.height)];
    
    UIImage*newImage=UIGraphicsGetImageFromCurrentImageContext();
    
    UIGraphicsEndImageContext();
    
    return newImage;
}

@end
